#include "codeRVisitor.h"
#include "ast.h"
#include "typedef.h"

void CodeRVisitor::visit(Node *n){
}

void CodeRVisitor::visit(Expr *n){
	
    if (n->unary_)
	{
		n->atom_->accept(codeRight);
		if(n->op_==NOT)
		{
			output<<"not i\n";
		}
		else output<<"neg i\n";	
	}
	else
	{
		n->left_->accept(this); 
		n->right_->accept(this); 
		
        switch (n->op_)
		{
		case ADD:
			output<<"add i \n";
			break;
		case MIN:
			output<<"sub i\n";
			break;
		case DIV:
			output<<"div i\n";
			break;
		case MUL:
			output<<"mul i\n";
			break;
		case EQU:
			output<<"equ i\n";
			break;
        case NEQ:
			output<<"neq i\n";
			break;            
		case LEQ:
			output<<"leq i\n";
			break;
		case LES:
			output<<"les i\n";
			break;
        case GRE:
			output<<"gre i\n";
			break;
        case GEQ:
			output<<"geq i\n";
			break;
        case OR:
            output<<"or \n";
			break;
        case AND:
            output<<"and \n";
			break;
        case NOT:
			output<<"not i\n";
			break;


		}
	}
	
}
void CodeRVisitor::visit(ExprList *n){
}
void CodeRVisitor::visit(Dim *n){
}
void CodeRVisitor::visit(Atom *n){
}
void CodeRVisitor::visit(IntConst *n){
	n->i_;
	output<<"ldc i "<<n->i_<<"\n";
}
void CodeRVisitor::visit(RealConst *n){
}
void CodeRVisitor::visit(True *n){
}
void CodeRVisitor::visit(False *n){
}
void CodeRVisitor::visit(Var *n){
}
void CodeRVisitor::visit(ArrayRef *n){
}
void CodeRVisitor::visit(RecordRef *n){
}
void CodeRVisitor::visit(AddressRef *n){
}
void CodeRVisitor::visit(Statement *n){
}
void CodeRVisitor::visit(Type *n){
}
void CodeRVisitor::visit(NewStatement *n){
}
void CodeRVisitor::visit(WriteStrStatement *n){
}
void CodeRVisitor::visit(WriteVarStatement *n){
}
void CodeRVisitor::visit(ProcedureStatement *n){
}
void CodeRVisitor::visit(Case *n){
}
void CodeRVisitor::visit(CaseList *n){
}
void CodeRVisitor::visit(CaseStatement *n){
}
void CodeRVisitor::visit(LoopStatement *n){
}
void CodeRVisitor::visit(ConditionalStatement *n){
}
void CodeRVisitor::visit(Assign *n){
}
void CodeRVisitor::visit(StatementList *n){
}
void CodeRVisitor::visit(Declaration *n){
}
void CodeRVisitor::visit(VariableDeclaration *n){
}
void CodeRVisitor::visit(RecordList *n){
}
void CodeRVisitor::visit(SimpleType *n){
}
void CodeRVisitor::visit(IdeType *n){
	if(n)
	n->accept(codeLeft);
	output<<"ind i \n";	
}
void CodeRVisitor::visit(ArrayType *n){
}
void CodeRVisitor::visit(RecordType *n){
}
void CodeRVisitor::visit(AddressType *n){
}
void CodeRVisitor::visit(Parameter *n){
}
void CodeRVisitor::visit(ByReferenceParameter *n){
}
void CodeRVisitor::visit(ParameterList *n){
}
void CodeRVisitor::visit(FunctionDeclaration *n){
}
void CodeRVisitor::visit(ProcedureDeclaration *n){
}
void CodeRVisitor::visit(DeclarationList *n){
}
void CodeRVisitor::visit(Block *n){
}
void CodeRVisitor::visit(Program *n){
}

/**
 OutputFile_ is the file that !you! (the students),
 write your output to;
 */
CodeRVisitor::CodeRVisitor(ostream & OutputFile_):
Visitor(OutputFile_)
{
}

CodeRVisitor::~CodeRVisitor()
{
}
